<template>
  <div id="videolist" class="page-full-screen">
    <div>
      <!--<el-button @click="addTit('新增')">新增</el-button>-->
      <!--<el-button @click="addTit('屏蔽')">屏蔽</el-button>-->
      <!--<el-button @click="addTit('解除屏蔽')">解除屏蔽</el-button>-->
      <!--<el-button @click="addTit('设置大咖')">设置大咖</el-button>-->
      <!--<el-button @click="addTit('设置用户组')">设置用户组</el-button>-->
      <el-button @click="searchshow = !searchshow">搜索&nbsp;<i :class="{active: searchshow === true}" class="iconfont icon-zhankai" style="font-size: 12px" />
      </el-button>
    </div>
    <el-collapse-transition>
      <div v-show="searchshow">
        <div class="main-box">
          <span>入驻企业</span>
          <el-select v-model="searchmsg.companyId" size="mini" placeholder="请选择">
            <el-option
                    v-for="item in videocateadd"
                    :key="item.id"
                    :label="item.title"
                    :value="item.id">
            </el-option>
          </el-select>
          <span style="margin-left: 20px"><el-button size="mini" @click="search">确定</el-button></span>
        </div>
      </div>
    </el-collapse-transition>
    <msg-list
      :table-data="tableData"
      :title="title"
      :btntype="btntype"
      :pagesall="parseInt(pagesall)"
      :pages="parseInt(page)"
      @getselect="getselect"
      @changepage="changepage1"
      @getid="getid1" />
    <div v-show="seecontent" class="layer">
      <div class="mask" @click="seecontent = false" />
      <div class="content">
        <span class="close" @click="seecontent = false"><i class="iconfont icon-untitled94" /></span>
        <p class="title">审核</p>
        <div class="main-box" style="text-align: center">
          <span style="margin-left: 50px;"><el-button @click="addTags('pass')">通过</el-button></span>
          <span style="margin-left: 50px;"><el-button @click="addTags('reject')">拒绝</el-button></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import msgbox from '../../common/msgbox.js'
import config from '../../common/config'
import MsgList from '../public/msgList'
import editor from '../../assets/editor/editor'
import ImgUpload from '../public/imgUpload'

export default {
  name: 'Index',
  components: {
    ImgUpload,
    MsgList,
    editor: editor
  },
  data() {
    return {
      allCode: [],
      inputCode: [],
      centerDialogVisible1: false,
      centerDialogVisible: false,
      page: 1,
      addtitle: '新增',
      enabled: 1,
      addvideo: {
        title: '',
        intro: '',
        website: '',
        icon: '',
        deal_code: '',
        download_url: '',
        order_num: 0,
        enabled: 1,
        content: '',
        aro_id: ''
      },
      searchmsg: {
        companyId: ''
      },
      btntype: ['审核'],
      pagesall: 0,
      content: {},
      type: true,
      deletes: {
        ids: [],
        reason: ''
      },
      delshow: false,
      searchshow: false,
      seecontent: false,
      title: [
        {
          prop: 'id',
          label: 'id'
        },
        {
          prop: 'title',
          label: '展厅名'
        },
        {
          prop: 'type',
          label: '会展类型'
        },
        {
          prop: 'sort',
          label: '排序'
        },
        {
          prop: 'url',
          label: 'VR地址'
        },
        {
          prop: 'verify_status',
          label: '审核状态'
        },
        {
          prop: 'enabled',
          label: '是否可用'
        }
      ],
      tableData: [],
      price: 0,
      intro: [],
      tid: 0,
      getmsg: {},
      videocateadd: [],
      userInfo: {
        info: {}
      },
      kaDiscount: '',
      activeName: '0'
    }
  },
  computed: {
    auditTitle() {
      return {
        0: '未提交',
        1: '审核中(打款申请中)',
        2: '审核中(打款金额待验证)',
        3: '审核中(待管理员审核)',
        9: '审核驳回',
        10: '审核通过'
      }
    }
  },
  mounted() {
    this.search()
  },
  methods: {
    search() { // 搜索获取数据
      const that = this
      this.$g.ajax({
        path: 'companies/getCompanyConvention',
        method: 'post',
        data: {
          companyId: this.searchmsg.companyId,
          page: this.page
        },
        cbSuccess: function(data) {
          that.tableData = data.memo.list
          if(data.memo.list.length > 0){
            for(let i in data.memo.list){
                if(data.memo.list[i].type === 0){
                    that.tableData[i].type = '图片展馆'
                }
                if(data.memo.list[i].type === 1){
                    that.tableData[i].type = 'VR展馆'
                }
                if(data.memo.list[i].verify_status === 0){
                    that.tableData[i].verify_status = '未审核'
                }
                if(data.memo.list[i].verify_status === 1){
                    that.tableData[i].verify_status = '审核失败'
                }
                if(data.memo.list[i].verify_status === 10){
                    that.tableData[i].verify_status = '审核通过'
                }
            }
          }
          that.pagesall = parseInt(data.memo.pageTotal)
          that.types()
        },
        cbError: function(data) {
          const msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    types() { // 获取分类数据
      let that = this
      this.$g.ajax({
          path: 'companies/searchCompany',
          method: 'get',
          cbSuccess: function (data) {
              that.videocateadd = data.memo
          },
          cbError: function (data) {
              let msg = msgbox.get(data.msg)
              that.$message.error(msg)
          }
      })
    },
    addTit(type) {
      const that = this
      if (type === '屏蔽' || type === '解除屏蔽') {
        let enabled = ''
        if (type === '屏蔽') {
          enabled = 0
        }
        if (type === '解除屏蔽') {
          enabled = 1
        }
        this.$g.ajax({
          path: 'companies/setEnabled',
          method: 'post',
          data: {
            ids: this.deletes.ids,
            enabled: enabled
          },
          cbSuccess: function(data) {
            that.search()
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      }
    },
    addTags(param) { // 添加/修改视频集
      let that = this
      this.$g.ajax({
          path: 'companies/setVerifyStatus',
          method: 'post',
          data: {
              conventionsId: that.tid,
              code: param === 'pass' ? 10 : 1
          },
          cbSuccess: function (data) {
              that.$message.success('保存成功')
              that.seecontent = false
              that.addvideo = {
                  companyId: '',
                  isResident: 0,
                  startDate: '',
                  endDate: '',
                  img: '',
                  intro: '',
                  orderNum: 0,
                  enabled: 1

              }
              that.setimg = ''
              that.search()
          },
          cbError: function (data) {
              let msg = msgbox.get(data.msg)
              that.$message.error(msg)
          }
      })
    },
    changepage1(page) { // 更改page
      this.page = page
      this.search()
    },
    delhot() {

    },
    getid1(val) { // 获取列表button信息
      const that = this
      if (val.btn === '删除') {
        this.tid = val.val.id
        this.delhot()
      }
      if (val.btn === '审核') {
          that.tid = val.val.id
          that.seecontent = true
          that.addtitle = '审核'
      }
    },
    getUserinfo() {
      const that = this
      this.$g.ajax({
        path: 'companies/getInfo',
        method: 'post',
        data: {
          id: that.tid
        },
        cbSuccess: function(data) {
          that.userInfo = data.memo
          that.userInfo.logo = data.memo.logo ? config.imgURI + data.memo.logo : null
          that.userInfo.license = data.memo.license ? config.imgURI + data.memo.license : null
          const { term_start, term_end, check_date, start_date, end_date } = that.userInfo.info
          that.userInfo.info.start_date = start_date ? that.$g.formatDate(parseInt(start_date), 'yyyy-mm-dd') : ' - '
          that.userInfo.info.end_date = end_date ? that.$g.formatDate(parseInt(end_date), 'yyyy-mm-dd') : ' - '
          that.userInfo.info.check_date = check_date ? that.$g.formatDate(parseInt(check_date), 'yyyy-mm-dd') : ' - '
          that.userInfo.info.term_start = term_start ? that.$g.formatDate(parseInt(term_start), 'yyyy-mm-dd') : ' - '
          that.userInfo.info.term_end = term_end ? that.$g.formatDate(parseInt(term_end), 'yyyy-mm-dd') : ' - '

          that.centerDialogVisible1 = true
        },
        cbError: function(data) {
          const msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    getselect(vals) { // 获取多选id
      this.deletes.ids = []
      for (const i in vals) {
        this.deletes.ids.push(vals[i].id)
      }
    },
    changemsg() {
      this.addvideo = {
        user_id: this.getmsg.val.id,
        begin_time: this.getmsg.val.begin_time,
        end_time: this.getmsg.val.end_time,
        id_card: this.getmsg.val.id_card
      }
      if (this.getmsg.enabled === 0) {
        this.enabled = 0
      }
      if (this.getmsg.enabled === 1) {
        this.enabled = 1
      }
    },
    setCode1(arr) {
      console.log(arr)
      const that = this
      this.$g.ajax({
        path: 'dealPoints/getList',
        method: 'post',
        data: {
          page: 'all'
        },
        cbSuccess: function(data) {
          that.allCode = data.memo.list
          that.$nextTick(() => {
            if (arr.length > 0) {
              for (const n in that.allCode) {
                for (const i in arr) {
                  if (arr[i].point_id === that.allCode[n].id) {
                    that.inputCode[arr[i].point_id] = arr[i].point
                  }
                }
              }
            } else {
              for (const i in that.allCode) {
                that.inputCode[that.allCode[i].id] = 0
              }
            }
          })
          that.$nextTick(() => {
            if (that.addtitle !== '设置大咖') {
              that.centerDialogVisible = true
            }
          })
        },
        cbError: function(data) {
          const msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    setCode() {
      const that = this
      let getData = []
      this.$g.ajax({
        path: 'users/getInfo',
        method: 'post',
        data: {
          user_id: that.tid
        },
        cbSuccess: function(data) {
          getData = data.memo.user_points
          that.setCode1(getData)
        },
        cbError: function(data) {
          const msg = msgbox.get(data.msg)
          that.$message.error(msg)
        }
      })
    },
    postCode() {
      const that = this
      const postArr = []
      for (const i in this.inputCode) {
        const postOne = {
          id: i,
          num: that.inputCode[i]
        }
        postArr.push(postOne)
      }
      this.$nextTick(() => {
        that.$g.ajax({
          path: 'users/setPoint',
          method: 'post',
          data: {
            user_id: that.tid,
            deals: postArr
          },
          cbSuccess: function(data) {
            that.inputCode = []
            that.centerDialogVisible = false
            that.$message.success('保存成功')
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      })
    },
    auditCompany(state) {
      if (this.userInfo.id) {
        const that = this
        that.$g.ajax({
          path: 'companies/setCheck',
          method: 'post',
          data: {
            ids: [this.userInfo.id],
            check: state
          },
          cbSuccess: function(data) {
            that.$message.success('操作成功')
            that.centerDialogVisible1 = false
            that.search()
          },
          cbError: function(data) {
            const msg = msgbox.get(data.msg)
            that.$message.error(msg)
          }
        })
      } else {
        return this.$message.info('企业信息错误，刷新后重试！')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.userinfo-class {
  padding: 20px;
  //border-bottom: 1px solid #cccccc;
  //text-align: center;

  .img-title {
    position: relative;
    top: -18px;
  }

  .item {
    padding: 5px 0;
    display: flex;
    .title {
      vertical-align: top;
      display: inline-block;
      min-width: 200px;
      text-align: right;
    }
  }

  img {
    width: 50px;
    height: 50px;
  }
}

.active {
  display: inline-block;
  -moz-transform: rotate(180deg);
  -webkit-transform: rotate(180deg);
  -o-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  transform: rotate(180deg);
}

#videolist {
  .main-box {
    margin-top: 20px;

    span {
      margin-right: 30px;
      font-size: 14px;
      font-weight: 700;
      color: #606266;
    }

    .el-input {
      width: 240px;
    }
  }

  .main-box {
    .el-radio__inner {
      background: red;
    }

    .el-radio__input.is-checked + .el-radio__label {
      color: #00a4a0 !important;
    }
  }

  .layer {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 999;
    overflow: hidden;

    .mask {
      background: rgba(153, 153, 153, 0.5);
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      z-index: 1;
    }

    .imgcontent {
      text-align: center;

      img {
        position: relative;
        max-width: 80%;
        max-height: 80%;
        background: #fff;
        margin: 5% auto;
        z-index: 3;
      }
    }

    .content {
      position: relative;
      width: 60%;
      max-height: 80%;
      background: #fff;
      margin: 5% auto;
      z-index: 2;
      padding: 30px;
      overflow: scroll;

      .close {
        position: absolute;
        right: 10px;
        top: 10px;
        cursor: pointer;
      }

      .inputcl {
        margin-top: 20px;

        .layer-list-title {
          display: inline-block;
          width: 80px;
          margin-left: 15px;
          margin-right: 10px;
          float: left;
          vertical-align: middle;
          line-height: 28px;
        }

        .img-list {
          vertical-align: top;
          float: left;
          line-height: 18px;
        }

        .imgupload {
          display: block;
          margin-left: 105px;
        }

        .imgupload1 {
          display: block;
          margin-left: 105px;
        }

        .main-cctv {
          min-height: 200px;
          border: 1px solid #cccccc;
        }

        .el-input {
          max-width: 200px;
        }

        img {
          width: 320px;
          height: 240px;
        }
      }

      .title {
        text-align: center;
        font-size: 18px;
        font-weight: bold;
      }

      .doit .one .el-input {
        width: 200px;
        margin-left: 20px;
      }

      .doit .one {
        margin-top: 20px;
        font-size: 14px;
      }

      .el-date-editor.el-input, .el-date-editor.el-input__inner {
        position: relative;
        left: -4px;
      }

      .buttons {
        margin-top: 20px;
        text-align: center;

        button {
          margin: 0 20px;
        }
      }
    }
  }
}

.code-ul {
  li {
    padding: 0 20px;
    margin-bottom: 10px;

    .el-input {
      max-width: 100% !important;
    }

    div:nth-of-type(1) {
      font-size: 14px;
      margin-bottom: 6px;
    }
  }
}
</style>
<style>
.el-button:focus, .el-button:hover {
  color: #00a4a0;
}

.el-button:active {
  border-color: #00a0a0;
}

.el-button {
  padding: 8px 14px;
}

.el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  background: #00a4a0;
  border-color: #00a4a0;
}

.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409EFF;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}

#videolist .el-textarea__inner {
  resize: none;
}
</style>
